package top.ranzhang.controller.admin;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.ranzhang.bean.entity.ParentCommunications;
import top.ranzhang.common.result.Result;
import top.ranzhang.service.IParentCommunicationsService;


/**
 * 家长沟通记录
 */
@RestController
@RequestMapping("/admin/parent-communications")
@RequiredArgsConstructor
public class ParentCommunicationsController {


    private final IParentCommunicationsService communicationService;


    /**
     * 创建考勤记录
     */
    @PostMapping
    public Result create(@RequestBody ParentCommunications communication) {
        communicationService.MSave(communication);
        return Result.success();
    }

    /**
     * 获取所有考勤记录
     */
    @GetMapping
    public Result getAll() {
        return Result.success(communicationService.getAll());
    }

    /**
     * 根据id获取考勤记录
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id) {
        return Result.success(communicationService.getById(id));
    }

    /**
     * 更新考勤记录
     */
    @PutMapping("/{id}")
    public Result update(@PathVariable Integer id, @RequestBody ParentCommunications communication) {
        communication.setCommunicationId(id);
        communicationService.update(communication);
        return Result.success();
    }

    /**
     * 删除考勤记录
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id) {
        communicationService.delete(id);
        return Result.success();
    }

}
